package com.simple.demo.sort;

import java.util.Arrays;

/**
 * 希尔排序
 */
public class XierSort {

    public static void main(String[] args) {
        int[] arr= {2,7,4,1,5,3,8,6,9,11,10};
        sort(arr);
        System.out.print(Arrays.toString(arr));
    }

    private static  void sort(int [] arr){
        for(int grap = arr.length/2; grap > 0 ; grap/=2){
            for(int star = grap ; star < arr.length ; star ++){
               int index = star - grap;
               for(;index >= 0 ; index-=grap){
                 if(arr[index] > arr[star]){
                   int temp = arr[index+grap];
                   arr[index+grap] = arr[index];
                   arr[index]=temp;
                 }else{
                     break;
                 }
               }
            }

        }
    }
}
